/**
 * Created by thomas on 2018/2/4.
 */
import common from "../common.js"
export default {
  //录音
  record_f:function(_this){
    r = plus.audio.getRecorder();
    r.record( {filename:"_doc/audio/"}, function (e) {
      alert( "Audio record success!fdsfsf" );
      // up_load(e);
      _this.voice_url = e
    }, function(e) {
      alert( "Audio record failed: " + e.message );
    });
  },
  //上传
  up_load:function(e,suc,fail){
  let base_url = common.get_base_url();
  let task = plus.uploader.createUpload(base_url+"/api/user/file/upload",
    {method:"POST"}, function ( t, status ) {
      console.log("tttttttttttttttttttttttt");
      console.log(status)
      // alert("ffff");
      console.log(JSON.stringify(t));
      //上传完成
      if ( status == 200 ) {
        suc(t)
        alert( "Upload success: " + t.url );
      } else {
        fail()
        alert( "Upload failed: " + status );
      }
    });
  console.log(e.toString())
  task.addFile(e, {key:"file"} );
  task.start();
  console.log("start——————————————————————————")
 },
  //播放
  play_music:function(url){
  mui.plusReady(function(){

    let p = plus.audio.createPlayer(url);

    p.play(function () {
      alert( "Audio play success!" );
    }, function ( e ) {
      alert( "Audio play failed: " + e.message );
    });
  })
}


}
